package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.mappers.BlackListMapper;
import com.tanhua.dubbo.mappers.UserInfoMapper;
import com.tanhua.model.db.BlackList;
import com.tanhua.model.db.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @program: tanhua
 * @description:
 * @author: MR.peng
 * @create: 2022-03-10 10:26
 **/
@DubboService
public class BlackListApiImpl implements BlackListApi{


    @Autowired
    private BlackListMapper blackListMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;

    /*
    *
    * */
    @Override
    public IPage<UserInfo> findByUserId(Long userId, Integer page, Integer pageSize) {
        //1.构造分页参数
        Page<UserInfo> pageParam = new Page<>(page,pageSize);
        //2.调用mapper查询
         return  userInfoMapper.findBlackList(pageParam,userId);
    }

    /*
    * 删除黑名单
    * */
    @Override
    public void delete(Long userId, Long blackUserId) {
        QueryWrapper<BlackList> qw = new QueryWrapper<>();
        qw.eq("user_id",userId);
        qw.eq("black_user_id",blackUserId);
        blackListMapper.delete(qw );
    }
}
